package com.example.everying.controller.chat;

import com.example.everying.annotation.WebLog;
import com.example.everying.constant.ChatMessageConstant;
import com.example.everying.context.UserContext;
import com.example.everying.model.dto.chat.ChatConversationDto;
import com.example.everying.model.dto.chat.ChatMessagePageDto;
import com.example.everying.model.entity.chat.ChatConversationEntity;
import com.example.everying.model.vo.chat.ChatCommentMessageVo;
import com.example.everying.model.vo.content.ActivityApplyVo;
import com.example.everying.model.vo.user.UserInfoVo;
import com.example.everying.service.chat.ChatConversationService;
import com.example.everying.service.chat.ChatMessagesService;
import com.example.everying.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "聊天")
@RequestMapping("/chat")
@RequiredArgsConstructor
public class ChatController {
    @Autowired
    private ChatMessagesService  chatMessagesService;
    @Autowired
    private ChatConversationService chatConversationService;

    @ApiOperation(value = "评论列表")
    @PostMapping("/comment/page")
    @WebLog(description = "评论列表")
    public Result<?> recharge(@ApiParam(name = "ChatMessagePageDto", value = "评论列表请求参数", required = true)
                              @RequestBody ChatMessagePageDto dto) {
        UserInfoVo userInfoVo = UserContext.getUser();
        if (userInfoVo == null){
            return Result.fail("用户未登录");
        }
        ChatMessagePageDto query = new ChatMessagePageDto();
        query.setUserId(userInfoVo.getId());
        query.setPage(dto.getPage());
        query.setLimit( dto.getLimit());
        query.setMessagesType(ChatMessageConstant.MESSAGE_TYPE_ACTIVITY_COMMENT);
        ChatCommentMessageVo chatCommentMessageVo = chatMessagesService.getCommentMessageList(query);
        return Result.ok(chatCommentMessageVo);
    }
    @ApiOperation(value = "获取会话信息")
    @ApiParam(name = "id", value = "id", required = true)
    @PostMapping("conversation")
    @WebLog(description = "获取会话信息")
    public Result<?> conversation(@ApiParam(name = "ChatConversationDto", value = "会话信息", required = true)
                               @RequestBody ChatConversationDto dto) {
        ChatConversationEntity entity =  chatConversationService.getConversation(dto.getFromUserId(),  dto.getToUserId());
        return   Result.ok(entity);
    }
}
